<!--专家指导-->
<template>
    <div class="home-guide-container">
        <div class="left-guide">
            <guide-source :cquestions="questions" :pageSize="pageSize" :total="total" @handleSearch="handleSearch"
                @pageClick="pageClick" @refresh="refresh">
            </guide-source>
        </div>
        <div class="right-guide">
            <div class="btn-content">
                <a @click="AllExBtn" style="cursor: pointer;">在线问答</a> |
                <a @click="AllExBtn" style="cursor: pointer;">专家预约</a>
            </div>
            <div class="professioner-item">
                <div style="font-size:18px;display: flex;justify-content: space-between;">
                    <strong>专家列表</strong>
                    <a style="font-size:12px;cursor: pointer;" @click="AllExBtn">更多专家>></a>
                </div>
                <div class="epert" v-for="(item, index) in expertArray" :key="index"
                    :style="index === expertArray.length - 1 ? '' : 'border-bottom: 1px dashed #f2f2f2;'">
                    <img src="@/assets/experts.png" alt="" />
                    <div class="info">
                        <div class="item-style">
                            <div class="content">专家姓名：{{ item.realName }}</div>
                            <div class="content">职称：{{ item.position }}</div>
                        </div>
                        <div class="item-style">
                            <div class="content">从事专业：{{ item.profession }}</div>
                            <div class="content">电话：{{ item.phone }}</div>
                        </div>
                        <div class="item-content">单位：{{ item.belong }}</div>
                        <div class="item-btn">
                            <div class="btn-item" @click="handleQuestion(item)"
                                v-if="!store.getters.isAdmin && !store.getters.isExpert">去提问</div>
                            <div class="btn-item" @click="handleAppointment(item)"
                                v-if="!store.getters.isAdmin && !store.getters.isExpert">去预约</div>
                        </div>
                    </div>
                </div>
                <!-- 分页 -->
                <div v-show="null !== expertArray && expertArray.length > 0"
                    style="width: 100%;display:flex;justify-content: center;margin-top: 10px;">
                    <el-pagination layout="prev, next" :page-size="epageSize" :total="etotal"
                        @current-change="handleCurrentChange" />
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import store from '@/store'
import { selectQuestions, selectExpert } from "@/api/order";
import GuideSource from '@/components/GuideSource.vue';
import { ref } from 'vue'
import { useRouter } from 'vue-router';

const router = useRouter()
const questions = ref([])
const total = ref(0)
const pageSize = ref(6)
const expertArray = ref([])
const searchValue = ref('')
const epageSize = ref(4)
const etotal = ref(0)

// 获取数据
const load = () => {
    selectQuestions({
        pageNum: 1,
        pageSize: pageSize.value
    }).then(res => {
        if (res.flag == true) {
            questions.value = res.data.data
            total.value = res.data.total
        }
    })
    selectExpert({
        pageNum: 1,
        pageSize: epageSize.value
    }).then(res => {
        if (res.flag == true) {
            expertArray.value = res.data.data
            etotal.value = res.data.total
        }
    })
    searchValue.value = ''
}
load()

//分页
const pageClick = (val) => {
    if (searchValue.value == '') {
        selectQuestions({
            pageNum: val,
            pageSize: pageSize.value,
        }).then(res => {
            if (res.flag == true) {
                questions.value = res.data.data
                total.value = res.data.total
            }
        })
    }
    if (searchValue.value != '') {
        selectQuestions({
            pageNum: val,
            pageSize: pageSize.value,
            keys: searchValue.value
        }).then(res => {
            if (res.flag == true) {
                questions.value = res.data.data
                total.value = res.data.total
            }
        })
    }
}

//搜索
const handleSearch = (val) => {
    searchValue.value = val
    selectQuestions({
        pageNum: 1,
        pageSize: pageSize.value,
        keys: searchValue.value
    }).then(res => {
        if (res.flag == true) {
            questions.value = res.data.data
            total.value = res.data.total
        }
    })
}


//刷新
const refresh = () => {
    load()
}


//专家数据分页
const handleCurrentChange = (val) => {
    if (searchValue.value == '') {
        selectExpert({
            pageNum: val,
            pageSize: epageSize.value
        }).then(res => {
            if (res.flag == true) {
                expertArray.value = res.data.data
            }
        })
    }
    if (searchValue.value != '') {
        selectExpert({})
    }
}

//跳转
const AllExBtn = () => {
    router.push("/index/all_experts").catch((err) => err);
}

</script>

<style lang="scss" scoped>
.home-guide-container {
    width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;

    .left-guide {
        margin-top: 10px;
    }

    .right-guide {
        .btn-content {
            margin-top: 10px;
            background-color: white;
            width: 350px;
            font-size: 16px;
            text-align: center;
            font-size: 18px;
            font-weight: bold;
            height: 40px;
            line-height: 40px;
        }

        .professioner-item {
            text-align: left;
            background-color: #fff;
            width: 350px;
            font-size: 12px;
            padding: 10px 20px;
            margin-top: 10px;
        }
    }
}


.epert {
    min-height: 80px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin-top: 20px;
    align-items: center;

    // padding: 10px 10px;
    img {
        width: 80px;
        height: 6 0px;
        margin-right: 10px;
        border-radius: 6px;
    }

    .item-style {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
    }

    p {
        margin: 5px;
    }

    .content {
        color: #333;
        font-size: 12px;
        font-style: normal;
        width: 120px;
        line-height: 25px;
    }

    .item-content {
        width: 220px;
        line-height: 25px;
        /*超出的部分隐藏*/
        overflow: hidden;
        /*文字用省略号替代超出的部分*/
        text-overflow: ellipsis;
        word-break: break-all;
        /*弹性伸缩盒子模型显示*/
        display: -webkit-box;
        /*限制在一个块元素显示文本的行数*/
        -webkit-line-clamp: 2;
        /*设置或检索伸缩盒对象的子元素排列方式*/
        -webkit-box-orient: vertical;
    }

    .item-btn {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        margin-bottom: 10px;
        margin-right: 10px;
        color: #67C23A;

        .btn-item {
            margin-left: 10px;
            cursor: pointer;

            &:hover {
                text-decoration: underline;
                color: #035D1C;
            }
        }
    }
}
</style>